package org.advanced.io;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;

/**
 * @author John.zhang
 * @version Id: Flush, v 1.0 2020/12/14 14:17 ZhiYong Exp $
 */
public class Flush {

    public static void main(String[] args) {
        try (BufferedOutputStream bufferedOutputStream =
                     new BufferedOutputStream(new FileOutputStream("C:/data/io/io01.txt"))) {
            bufferedOutputStream.write("Hello World".getBytes());
            //缓冲区满了才会写出去；所以这里需要主动flush
            //1.第一种刷盘flush()
            //2.第二种 其实try()本身也会自动flush，因为调用了.closed() 这里内部也会调用flush()
            bufferedOutputStream.flush();
        } catch (Exception e) {

        }

    }

}
